package com.whg.opengl;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;

import com.whg.opengl.shape.Triangle;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

/**
 * author : Whg
 * e-mail : guanhuawei@ksjgs.com
 * date   : 2019-10-1109:06
 * desc   :
 * version: 1.0
 * Stay hungry,stay foolish.
 */
public class FGLRender implements GLSurfaceView.Renderer {

    private final FGLView mFGLView;
    Triangle triangle;

    public FGLRender(FGLView fglView) {
        this.mFGLView = fglView;
    }

    @Override
    public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
        //清空颜色
        GLES20.glClearColor(0, 0, 0, 0);
        triangle = new Triangle();

    }

    @Override
    public void onSurfaceChanged(GL10 gl10, int width, int height) {
        triangle.onSurfaceChanged(gl10, width, height);

    }

    /**
     * 不断被调用
     *
     * @param gl10
     */
    @Override
    public void onDrawFrame(GL10 gl10) {
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
        triangle.onDrawFrame(gl10);
    }
}
